require "import"
import "str"

--pid=...

--rc4=import "mods.minicrypto"

--import "android.support.v4.app.*"
--import "android.support.v4.view.*"
import "android.support.v4.widget.*"

topbar_click=0

--this.debug=true
--print(nmo)

this.setContentView(loadlayout ({
  RelativeLayout,
  --layout_width="fill",
  --layout_height="fill",
  --visibility=4,
  backgroundColor=背景色,
  --orientation="vertical",
  --elevation="2%w",
  paddingTop=状态栏高度,
  {
    RelativeLayout,
    layout_width="fill",
    layout_height="56dp" ,
    gravity="center",
    padding="16dp",
    --backgroundColor=0xffffffff,
    elevation="2dp",
    paddingTop="8dp",
    paddingBottom="8dp",
    onClick=function()
      if topbar_click+2 > tonumber(os.time()) then
        ObjectAnimator.ofInt(loadb, "scrollY", {loadb.scrollY,0})
        .setDuration(256)
        .setInterpolator(luajava.newInstance("android.view.animation.DecelerateInterpolator"))
        .start()
       else
        topbar_click=tonumber(os.time())
      end
    end;
    {
      ImageView,
      src="drawable/back.png",
      layout_height="fill",
      layout_width="44dp",
      foreground=波纹(波纹色),
      onClick=function ()
        this.finish()
      end,
      padding="9dp",
      colorFilter=图标色,
    },
    
    {
      TextView,
      layout_width="fill",
      layout_height="fill",
      gravity="center",
      --layout_gravity="center",
      text="今日志",
      textSize="20sp",
      textColor=文字色,
    },
  },
{
    SwipeRefreshLayout;
    id="swipe";
    layout_height="-1";
    layout_width="-1";
  {
      ScrollView,
      layout_height="-1";
      layout_width="-1";
      id="loadb";
      {
        LinearLayout,
        layout_width="fill",
        --layout_height="-1";
        orientation="vertical",
     --  layoutTransition=LayoutTransition(),
   -- .enableTransitionType(4),
        {
          LinearLayout,
          paddingTop="56dp" ,
        };
        
        
        {
          LinearLayout,
          layout_width=-1,
          layout_height="100dp",
          padding="10dp",
          layout_margin="16dp",
          layout_marginTop="8dp",
          layout_marginBottom=0,
          
         gravity=17,
      --   visibility=8,
          id="timeReport",
          foreground=波纹(背景色,圆角(nil,-1,{20,20,20,20,20,20,20,20})),
          backgroundDrawable=圆角(nil,图标色,{20,20,20,20,20,20,20,20}),
          {
            TextView,
            id="timeCate",
            textSize="16sp",
            textColor=背景色,
          },
          {
            TextView,
            id="timeHour",
        --    padding=0,
        padding="4dp",
            textSize="36sp",
            textColor=背景色,
          },
          {
            TextView,
            text="时",
            textSize="16sp",
            
            textColor=背景色,
            
          },
          {
            TextView,
            id="timeMinute",
        --    padding=0,
        padding="4dp",
            textSize="36sp",
            textColor=背景色,
          },
          {
            TextView,
            text="分",
            textSize="16sp",
            layout_marginRight="8dp",
            textColor=背景色,
            layout_weight=1,
            layout_width=-1,
          },
   {
            TextView,
            text="报时",
            textSize="16sp",
            textColor=背景色,
            
            
            
          },
          
          {
            ImageView,
            layout_width="24dp",
            layout_height="24dp",
         --   layout_height=-1,
         
          --  layout_weight=1,
            colorFilter=背景色,
           
            src="drawable/play_arrow.png",
         layout_marginLeft="4dp",
          },
          
          
      
        },


        {
            LinearLayout,
            layout_width="fill",
          --  layout_weight=1,
            layout_margin="16dp",
            layout_marginBottom="4dp",
            backgroundDrawable=波纹(波纹色,圆角(nil,文字色,{70,70,70,70,70,70,70,70})),
            gravity=17,
            onClick=function ()
              this.newActivity("app/more/day/summary")
            end,
            --padding="16sp",
            minimumHeight="56sp",
            padding="10dp",
            orientation=1,
            id="summary",
            layoutTransition=LayoutTransition()
        .enableTransitionType(4),
  --       .enableTransitionType(2)
   --       .enableTransitionType(1)
        --   .enableTransitionType(0)
     --   .enableTransitionType(3),
            {
             LinearLayout,
             gravity=17,
             {
              TextView,
              textSize="16sp",
              textColor=文字色,
              text="今日总结",
             },
             {
              ImageView,
              layout_width="24dp",
              layout_height="24dp",
              layout_marginLeft="8dp",
              rotation=-90,
              src="drawable/arrow.png",
              colorFilter=图标色,
             },
            },
            {
              TextView,
              layout_marginTop="6dp",
              visibility=8,
              textSize="14sp",
              textColor=次要文字色,
              --text="今日总结",
              id="summaryDate",
             },
            
          },
        
        {
          LinearLayout,
          layout_width="fill",
            {
            LinearLayout,
            layout_width="fill",
            layout_weight=1,
            layout_margin="4dp",
            layout_marginLeft="16dp",
            backgroundDrawable=波纹(波纹色,圆角(nil,文字色,{70,70,70,70,70,70,70,70})),
            gravity=17,
            onClick=function ()
              this.newActivity("app/more/day/what_happen")
            end,
            --padding="16sp",
            minimumHeight="56sp",
            {
              TextView,
              textSize="16sp",
              textColor=文字色,
              text="历史上的今天",
            },
            {
              ImageView,
              layout_width="24dp",
              layout_height="24dp",
              layout_marginLeft="8dp",
              rotation=-90,
              src="drawable/arrow.png",
              colorFilter=图标色,
            },
          },
          {
            LinearLayout,
            layout_width="fill",
            layout_weight=1,
            layout_margin="4dp",
            layout_marginRight="16dp",
            backgroundDrawable=波纹(波纹色,圆角(nil,文字色,{70,70,70,70,70,70,70,70})),
            gravity=17,
            onClick=function ()
              this.newActivity("app/more/day/birth")
            end,
            --padding="16sp",
            minimumHeight="56sp",
            {
              TextView,
              textSize="16sp",
              textColor=文字色,
              text="伟人生日",
            },
            {
              ImageView,
              layout_width="24dp",
              layout_height="24dp",
              layout_marginLeft="8dp",
              rotation=-90,
              src="drawable/arrow.png",
              colorFilter=图标色,
            },
          },
        },
        
        {
          LinearLayout,
          layout_width="fill",
            {
            LinearLayout,
            layout_width="fill",
            layout_weight=1,
            layout_margin="4dp",
            layout_marginLeft="16dp",
            backgroundDrawable=波纹(波纹色,圆角(nil,文字色,{70,70,70,70,70,70,70,70})),
            gravity=17,
            onClick=function ()
              this.newActivity("app/more/day/gone")
            end,
            --padding="16sp",
            minimumHeight="56sp",
            {
              TextView,
              textSize="16sp",
              textColor=文字色,
              text="伟人逝世",
            },
            {
              ImageView,
              layout_width="24dp",
              layout_height="24dp",
              layout_marginLeft="8dp",
              rotation=-90,
              src="drawable/arrow.png",
              colorFilter=图标色,
            },
          },
          {
            LinearLayout,
            layout_width="fill",
            layout_weight=1,
            layout_margin="4dp",
            layout_marginRight="16dp",
            backgroundDrawable=波纹(波纹色,圆角(nil,文字色,{70,70,70,70,70,70,70,70})),
            gravity=17,
            onClick=function ()
              this.newActivity("app/more/day/festival")
            end,
            --padding="16sp",
            minimumHeight="56sp",
            {
              TextView,
              textSize="16sp",
              textColor=文字色,
              text="节日与风俗",
            },
            {
              ImageView,
              layout_width="24dp",
              layout_height="24dp",
              layout_marginLeft="8dp",
              rotation=-90,
              src="drawable/arrow.png",
              colorFilter=图标色,
            },
          },
        },
        
        
        {
          LinearLayout,
          layout_margin="16dp",
          layout_marginTop="8dp",
          layout_marginBottom="8dp",
          orientation=1,
          visibility=8,
          layout_width=-1,
          id="word",
          layoutTransition=LayoutTransition()
        .enableTransitionType(4),
          onClick=function()
             --getWord()
             this.newActivity("soup",{wordCn.text.."\n\n"..wordEn.text})
          end,
          foreground=波纹(波纹色,圆角(nil,-1,{20,20,20,20,20,20,20,20})),
          backgroundDrawable=圆角(nil,图标色==-1&&0x08ffffff||0x10000000,{20,20,20,20,20,20,20,20}),
          padding="10dp",
          {
            ImageView,
            layout_width="24dp",
            layout_height="24dp",
            colorFilter=图标色,
            src="drawable/quote.png",
            rotation=180,
            layout_marginBottom="6dp",
          },
         
          {
            TextView,
            textSize="16sp",
            textColor=文字色,
            id="wordCn",
            layout_marginLeft="3dp",
            layout_marginBottom="2dp",
          },
          {
            TextView,
            textSize="14sp",
            textColor=次要文字色,
            id="wordEn",
            layout_marginLeft="3dp",
          },
        },
        
        
        
        {
          CardView,
          layout_margin="16dp",
          layout_marginTop="8dp",
          layoutTransition=LayoutTransition()
        .enableTransitionType(4),
          layout_marginBottom="8dp",
          radius="12dp",
          elevation=0,
          layout_width=-1,
          backgroundColor=0,
          {
            ImageView,
            layout_width=-1,
            adjustViewBounds=true,
            id="welcome",
            src="http://fimg.jpszx.com",
          },
        },
        
        
        
       
      },
    },
  },
  {
    LinearLayout,
    layout_width="fill",
    layout_height="56dp" ,
    foreground=上下渐变({背景色,深透,淡透}),
  },
}))

function getWord()
Http.get(
getApiUrl("api","api/enapi.php"), function (c,n)
if c!=200 then
return
end
--this.debug=true
n=cjson.decode(n)
--print(dump(n))
if n.code!=1 then
return
end
local data=n.data
word.visibility=0
wordCn.text=data.zh
wordEn.text=data.en
end
)
end

getWord()

function getSummary()
Http.get("http://jieri.jpszx.com/day/yulan/xz.php", function(c,n)
if c!=200 then
return
end
summary.post(function()
summaryDate.text=Html.fromHtml(n)
summaryDate.visibility=0
summary.gravity=3
end)
end)
end

getSummary()

swipe.setProgressViewOffset(true,dp2px(56),dp2px(32+56))
 .setColorSchemeColors({文字色})
 .setProgressBackgroundColorSchemeColor(背景色)
 .onRefresh=function()
   getWord()
   getSummary()
   this.newTask(function(p)
          require"import"
          return loadbitmap("http://fimg.jpszx.com")
        end,nil, function (b)
          welcome.setImageBitmap(b)
        end).execute{}
    swipe.refreshing=false
 end

--this.debug=true

local function checkTime()
--time.text=Html.fromHtml("现在是早上 <big><big><big><big>7</big></big></big></big> 时")
--print(os.date("%M"))
--[[local m=os.date("%M")+0
if m>5&&m<55 then
timeReport.visibility=8
return
end
timeReport.visibility=0]]
local h=tointeger(os.date("%H"))
timeMinute.text=tointeger(os.date("%M"))..""
local cate
if h<4 then
cate="凌晨"
elseif h<7 then
cate="清晨"
elseif h<11 then
cate="上午"
elseif h<13 then
cate="中午"
elseif h<17 then
cate="下午"
elseif h<19 then
cate="傍晚"
else
cate="晚上"
end
if h>12 then
h=h-12
end
timeCate.text="现在是"..cate
timeHour.text=""..h
end

checkTime()

local tick=Ticker()
.setPeriod(1000)
tick.onTick=checkTime

tick.start()

local mp
timeReport.onClick=function()
           --[[Http.get(
               getApiUrl("api","api/baoshi.php?msg="..os.date("%H")..":00"), 
               function(c, n)
                 if c!=200 then
                   toast"加载报时语音错误"
                   return
                 end
--this.debug=true]]
              if mp==nil then
import"android.media.MediaPlayer"
local r,e=pcall(function ()
                mp=MediaPlayer()
              .setOnErrorListener{onError=function(m,i,i2)
                    if i2!=0 then
                      toast("加载报时语音错误")
                    end
                end}
                .setOnPreparedListener{onPrepared=function(m)
                  m.start()
                end}
                end)
            if !r then
 toast("加载报时语音错误")
 return
 end
               else
                mp.reset()
              end
toast("正在加载报时语音")
local h=os.date("%H")
if h==0 then
h==24
end
              mp.setDataSource("http://api.jpszx.com/api/data/baoshi/"..tointeger(h)..".mp3")
              .prepareAsync()
              .start()
              
           --  end)
          end

function onPause()
tick.enabled=false
end

function onResume()
tick.enabled=true
end

function onDestroy()
tick.stop()
if mp then
mp.stop()
mp.release()
end
end
